// 时间转换 时:分:秒 -> 秒

#include <iostream>
using namespace std;

#include <stdlib.h>

void GetTime(int* hour, int* min, int* sec);

int CalcSeconds(int hour, int min, int sec);

int main() {
    cout << "欢迎使用时间转换程序!\n";

    char ch;
    do {
        int hour, min, sec;
        GetTime(&hour, &min, &sec);

        cout << "你输入的时间是 " << hour << ":" << min << ":" << sec << "\n";
        cout << "等于 " << CalcSeconds(hour, min, sec) << " 秒\n";

        cout << "再运行一次吗? y或n: ";
        cin >> ch;
    } while (ch == 'y' || ch == 'Y');
}

void GetTime(int* hour, int* min, int* sec) {
    while (true) {
        cout << "请输入时:分:秒\n";
        cout << "例如 4:15:34 (注意分和秒小于60): ";

        char colon;
        cin >> *hour >> colon >> *min >> colon >> *sec;
        if (*min > 59 || *sec > 59) {
            cout << "嘿! 时间错误!\n";
        }
        else {
            break;
        }
    }
}

int CalcSeconds(int hour, int min, int sec) {
    return hour * 3600 + min * 60 + sec;
}
